<?php
/**
 * 单请求中，保存对象  
 *
 * @filesource _singleton.php
 * @package peck 
 * @subpackage _singleton
 * @version $id: 0.1, utf8, Tue Jun 29 15:00:14 CST 2010$
 * @author LD King <kldscs[at]gmail.com>
 * @example 
 *   
 */
class _singleton{

   /**
    * 保存在 $GLOBALS['__singles']
    */ 

    private function __construct(){}
    private function __clone(){}

    public static function object(){
        $oo = '__objects';
        $key = 'singleton';
        if( !empty($GLOBALS[$oo][$key]) ){
            if( $GLOBALS[$oo][$key] instanceof self){
                return $GLOBALS[$oo][$key];
            }
        }
        
        $object = new self();
        $GLOBALS[$oo][$key] = $object;
        return $GLOBALS[$oo][$key];
    } 

    public function __get($key){
        $oo = '__singles';
        return isset($GLOBALS[$oo][$key]) 
            ? $GLOBALS[$oo][$key] : null;
    }

    public function __set($key, $value){
        $GLOBALS['__singles'][$key] = $value;
    }

}


